package cn.com.pxto.web.tag;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class DateFormatTag extends SimpleTagSupport {
	private String value = null;
	//private String pattern = "yyyy-MM-dd";
	private String pattern = "yyyy-MM-dd HH:mm:ss";
	public void setValue(String value) {
		this.value = value;
	}

	public void setPattern(String pattern) {
		this.pattern = pattern;
	}

	public void doTag() throws JspException, IOException {
		String dateValue = "";
		if (value.length()>1){
			long longValue = Long.parseLong(value);
			SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
			dateValue = dateFormat.format(new Date(longValue));
		}
		getJspContext().getOut().print(dateValue);
		super.doTag();
	}
}

